﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
/// <summary>
/// Summary description for ClassThueCD
/// </summary>
public class ClassThueCD
{
	public ClassThueCD()
	{
		//
		// TODO: Add constructor logic here
		//
	}
    DataConnection data = new DataConnection();
    //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++Thue CD+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    //---------------------------------------------------------------------load data-----------------------------------------------------
    public DataTable DSThueCD()
    {
        string sql = "select MaThue,ThueCD.MaKH,HoTen,NgayThue,NgayPhaiTra,NgayTra from ThueCD,KhachHang where ThueCD.MaKH=KhachHang.MaKH";
        return data.GetData(sql);
    }
    //---------------------------------------------------------------------search data-----------------------------------------------------
    public DataTable TimThueCD(string khhang,string ngaythuet,string ngaythued)
    {
        string sql = "select MaThue,ThueCD.MaKH,HoTen,NgayThue,NgayPhaiTra,NgayTra from ThueCD,KhachHang where ThueCD.MaKH=KhachHang.MaKH";
        if (khhang != null)
            sql = sql + " and HoTen like '%'+@khhang+'%'";
        if (ngaythuet != null && ngaythued != null)
            sql = sql + " and NgayThue between @ngaythuet and @ngaythueden";
        SqlParameter pkh = new SqlParameter("@khhang", khhang);
        SqlParameter pngt = new SqlParameter("@ngaythuet", ngaythuet);
        SqlParameter pngd = new SqlParameter("@ngaythueden", ngaythued);
        return data.GetData(sql, pkh,pngt,pngd);
    }
    //---------------------------------------------------------------------delete_insert_updata data-----------------------------------------------------
    public DataTable XoaThueCD(int ma)
    {
        string xoa = "delete from ThueCD where MaThue=@ma";
        SqlParameter pxoa = new SqlParameter("@ma", ma);
        return data.GetData(xoa, pxoa);
    }
    public DataTable ThemThueCD(int mkh, string ngayt, string ngaypt,string  ngaytra)
    {
        SqlParameter pmkh = new SqlParameter("@MaKH", mkh);
        SqlParameter pnt= new SqlParameter("@NgayThue", ngayt);
        SqlParameter pnpt = new SqlParameter("@NgayPhaiTra", ngaypt);
        SqlParameter pntr = new SqlParameter("@NgayTra", ngaytra);
        string sql = "insert into ThueCD values(@MaKH,@NgayThue,@NgayPhaiTra,@NgayTra)";
        return data.GetData(sql,pmkh, pnt, pnpt, pntr);
    }
    public DataTable SuaCD(int mthue, int mkh, string ngayt, string ngaypt, string ngaytra)
    {
        SqlParameter pmt = new SqlParameter("@mt", mthue);
        SqlParameter pmkh = new SqlParameter("@mkh", mkh);
        SqlParameter pnt = new SqlParameter("@nt", ngayt);
        SqlParameter pnpt = new SqlParameter("@npt", ngaypt);
        SqlParameter pntr = new SqlParameter("@ntr", ngaytra);

        string sql = "update ThueCD set MaKH=@mkh,NgayThue=@nt,NgayPhaiTra=@npt,NgayTra=@ntr where MaThue=@mt";
        return data.GetData(sql, pmt, pmkh, pnt, pnpt, pntr);
    }
    //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    //-------------------------------------------------------------------------CTThueCD-----------------------------------------------------------------
    public DataTable ThemCTThueCD(int mphim,int sl, int slg, int slt, float gt)
    {
        SqlParameter psl = new SqlParameter("@SoLuong", sl);
        SqlParameter pslg = new SqlParameter("@SoLuongGiao", slg);
        SqlParameter pslt = new SqlParameter("@SoLuongTra", slt);
        SqlParameter pgt = new SqlParameter("@GiaThue", gt);
        SqlParameter pmphim = new SqlParameter("@MaPhim", mphim);
        string sql = "insert into ChiTietThueCD values(@MaPhim,@SoLuong,@SoLuongGiao,@SoLuongTra,@GiaThue)";
        return data.GetData(sql,pmphim, psl, pslg, pslt, pgt);
    }
    public DataTable DSCTThueCD()
    {
        string sql = "select * from ChiTietThueCD ";
        return data.GetData(sql);
    }
    public DataTable XoaCTThueCD(int ma)
    {
        string xoa = "delete from ChiTietThueCD where MaThue=@ma";
        SqlParameter pxoa = new SqlParameter("@ma", ma);
        return data.GetData(xoa, pxoa);
    }
    public DataTable SuaCTCD(int mthue, int mCD,int sl, int slg, int slt, float gt)
    {
        SqlParameter pmt = new SqlParameter("@mt", mthue);
        SqlParameter pmcd = new SqlParameter("@MaCD", mCD);
        SqlParameter psl = new SqlParameter("@SoLuong", sl);
        SqlParameter pslg = new SqlParameter("@SoLuongGiao", slg);
        SqlParameter pslt = new SqlParameter("@SoLuongTra", slt);
        SqlParameter pgt = new SqlParameter("@GiaThue", gt);

        string sql = "update ChiTietThueCD set MaPhim=@MaCD ,SoMuon=@SoLuong,SoGiao=@SoLuongGiao,SoTra=@SoLuongTra,GiaThue=@GiaThue where MaThue=@mt";
        return data.GetData(sql, pmt, pmcd, psl, pslg, pslt, pgt);
    }
    //-------------------------------------------------------------------Giohang----------------------------------------------------------------------
    public DataTable LuugioHang(string tenCD, int sl, float gt, float thanhtien)
    {
        SqlParameter ptencd = new SqlParameter("@tenCD", tenCD);
        SqlParameter psl = new SqlParameter("@SoLuong", sl);
        SqlParameter pgt = new SqlParameter("@GiaThue", gt);
        SqlParameter ptt = new SqlParameter("@ThanhTien", thanhtien);

        string sql = "insert into GioHang values(@tenCD,@SoLuong,@GiaThue,@ThanhTien)";
        return data.GetData(sql, ptencd, psl, pgt,ptt);
    }
}
